<?php
/**
 * Created by PhpStorm.
 * User: dreamy
 * Date: 2019-06-22
 * Time: 09:31
 */
use yii\helpers\Html;
?>

<?=Html::cssFile('@web/static/css/index.css')?>
<?php echo $this->render('../public/ele.php')?>
<!--引入页面头部-->
<?php echo $this->render('../public/header.php')?>
<!--引入账本样式-->
<?=Html::cssFile('@web/static/css/tally.css')?>
<?=Html::jsFile('@web/static/js/jquery-3.4.1.min.js')?>
<div class="bg1">
    <div id="bg1-c"></div>
</div>
<div id="mainContent" style="display: none;" :style="{display: 'block'}">
    <el-row>
        <el-col :span="3">
            <div class="tallyAdd" v-on:click="tallyAddDialog">
                <i class="el-icon-plus"></i>
                新增账本
            </div>
            <el-scrollbar>
                <div id="tallyList">
                    <div  v-for="(item, index) in tallyList">
                        <el-card shadow="hover" class="tallyItemWrap" v-bind:class="{'active':item.id == currentTallyId}">
                            <div class="tallyItem" data-id="{{ item.id }}"  @click="location.href='/tally?id='+item.id">
                                <el-tooltip placement="right">
                                    <div slot="content">{{ item.company_title }}
                                        <br/>{{ item.city }}.{{ item.province }}
                                        <br/>{{ item.memo }}
                                    </div>
                                    <p class="tallyTitle">
                                        {{ item.title }}
                                    </p>
                                </el-tooltip>
                            </div>
                        </el-card>
                    </div>
                </div>
            </el-scrollbar>
        </el-col>
        <el-col :span="21">
            <el-tabs type="border-card" v-model="activeTab" class="tallyNavItem" @tab-click="handleTabClick">
                <el-tab-pane name="record">
                    <span slot="label"><i class="el-icon-plus"></i> 记一笔</span>
                    <div id="tallyRecordBox">
                        <div id="operationArea">
                            <el-row>
                                <el-button v-if="tallyAddType == 10" type="primary" size="small" round>记收入</el-button>
                                <el-button v-if="tallyAddType != 10" type="default" size="small" round @click="setTallyAddType(10)">记收入</el-button>
                                <el-button v-if="tallyAddType == 20" type="primary" size="small" round>记支出</el-button>
                                <el-button v-if="tallyAddType != 20" type="default" size="small" round @click="setTallyAddType(20)">记支出</el-button>
                                <el-button v-if="tallyAddType == 30" type="primary" size="small" round>记转账</el-button>
                                <el-button v-if="tallyAddType != 30" type="default" size="small" round @click="setTallyAddType(30)">记转账</el-button>
                            </el-row>
                        </div>
                        <div class="tallyRecordForm">
                            <el-row>
                                <el-col :span="24">
                                    <el-form :inline="true" :model="tallyRecordForm" :rules="tallyFormRules" class="form-inline recordForm">
                                        <el-form-item size="mini" prop="account_id">
                                            <span slot="label">{{ tallyAddType == 30 ? "转出":"账户" }}</span>
                                            <el-select placeholder="账户" clearable filterable default-first-option v-model="tallyRecordForm.account_id" @click.native="getAccountList()">
                                                <el-option
                                                        v-for="item in accountList"
                                                        :key="item.id"
                                                        :label="item.title"
                                                        :value="item.id">
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item size="mini" prop="account_dst_id" v-if="tallyAddType == 30">
                                            <span slot="label">转入</span>
                                            <el-select placeholder="转入" clearable filterable default-first-option v-model="tallyRecordForm.account_dst_id">
                                                <el-option
                                                        v-for="item in accountList"
                                                        :key="item.id"
                                                        :label="item.title"
                                                        :value="item.id">
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item v-if="tallyAddType == 10 || tallyAddType == 20" label="分类" size="mini">
                                            <el-select  placeholder="分类" clearable filterable default-first-option v-model="tallyRecordForm.category_id" filterable @click.native="getCategoryList()">
                                                <el-option-group
                                                    v-for="cate in categoryList"
                                                    :key="cate.title"
                                                    :label="cate.title">
                                                    <el-option
                                                            v-for="item in cate.children"
                                                            :key="item.id"
                                                            :label="item.title"
                                                            :value="item.id">
                                                    </el-option>
                                                </el-option-group>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="金额" size="mini" prop="amount">
                                            <el-input placeholder="金额" v-model="tallyRecordForm.amount"></el-input>
                                        </el-form-item>

                                        <el-form-item v-if="tallyAddType == 10" label="客户" size="mini">
                                            <el-select  placeholder="客户" clearable filterable default-first-option v-model="tallyRecordForm.store_id" @click.native="getStoreList(1)">
                                                <el-option
                                                        v-for="item in storeList"
                                                        :key="item.id"
                                                        :label="item.title"
                                                        :value="item.id">
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item v-if="tallyAddType == 20" label="供应商" size="mini">
                                            <el-select  placeholder="供应商" clearable filterable default-first-option v-model="tallyRecordForm.store_id" @click.native="getStoreList(2)">
                                                <el-option
                                                        v-for="item in storeList"
                                                        :key="item.id"
                                                        :label="item.title"
                                                        :value="item.id">
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="员工" size="mini">
                                            <el-select  placeholder="员工" clearable filterable default-first-option v-model="tallyRecordForm.member_id" @click.native="getMemberList()">
                                                <el-option
                                                        v-for="item in memberList"
                                                        :key="item.id"
                                                        :label="item.name"
                                                        :value="item.id">
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="项目" size="mini">
                                            <el-select  placeholder="项目" clearable filterable default-first-option v-model="tallyRecordForm.project_id"  @click.native="getProjectList()">
                                                <el-option
                                                        v-for="item in projectList"
                                                        :key="item.id"
                                                        :label="item.title"
                                                        :value="item.id">
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="时间" size="mini">
                                            <el-date-picker class="datePicker" v-model="tallyRecordForm.dateR" placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
                                            ~
                                            <el-time-picker class="timePicker" v-model="tallyRecordForm.timeR" placeholder="选择时间" value-format="HH:mm:ss"></el-time-picker>
                                        </el-form-item>
                                        <p style="margin-bottom: 10px;">
                                            <el-link :underline="false" type="primary"  @click="showImgUploadBox = !showImgUploadBox"><i class="el-icon-picture-outline"></i>&nbsp;添加图片</el-link>
                                            <el-upload v-if="showImgUploadBox" accept="image/jpeg,image/gif,image/png"
                                                       action="/api/upload/img" :headers="upHeaders"
                                                       :file-list="recordFormFileList"
                                                       :on-success="recordFormFileUploadSuccess"
                                                       :on-remove="recordFormFileRemove"
                                                    list-type="picture-card" :limit="3">
                                                <i class="el-icon-plus"></i>
                                            </el-upload>
                                            <el-dialog :visible.sync="dialogVisible">
                                                <img width="100%" :src="dialogImageUrl" alt="">
                                            </el-dialog>
                                        </p>
                                        <p>
                                            <el-form-item label="备注" size="mini">
                                                <el-input placeholder="备注" class="tallyMemoInput" v-model="tallyRecordForm.memo"></el-input>
                                            </el-form-item>
                                            <el-button type="primary" size="mini" @click="handleRecordForm">创建记录</el-button>
                                        </p>
                                    </el-form>
                                </el-col>
                            </el-row>
                            <div class="recordListBox">
                                <el-card class="box-card">
                                    <div slot="header" class="clearfix">
                                        <span>账目清单</span>
                                        <el-divider direction="vertical"></el-divider>
                                        <span>{{ recordPeriod }}</span>
                                        <div class="recordStatRight">
                                            总支出：
                                            <span class="green number" id="ft-payout">-{{ recordCountDebt.out }}</span>
                                            <el-divider direction="vertical"></el-divider>
                                            总收入：
                                            <span class="orange number" id="ft-payout">{{ recordCountDebt.in }}</span>
                                            <el-divider direction="vertical"></el-divider>
                                            结余：
                                            <span class="gray number" id="ft-payout">{{ recordCountDebt.debt }}</span>
                                        </div>
                                    </div>
                                    <!--条件筛选账单表单-->
                                    <div class="recordSearchBox">
                                        <el-form :inline="true" v-model="recordSearchForm" class="form-inline recordSearchForm">
                                            <el-form-item size="mini">
                                                <el-select  placeholder="全部分类" clearable filterable default-first-option v-model="recordSearchForm.category_id" filterable @click.native="getCategoryList()">
                                                    <el-option-group
                                                            v-for="cate in categoryList"
                                                            :key="cate.title"
                                                            :label="cate.title">
                                                        <el-option
                                                                v-for="item in cate.children"
                                                                :key="item.id"
                                                                :label="item.title"
                                                                :value="item.id">
                                                        </el-option>
                                                    </el-option-group>
                                                </el-select>
                                            </el-form-item>
                                            <el-form-item size="mini">
                                                <el-select placeholder="全部账户" clearable filterable default-first-option v-model="recordSearchForm.account_id" @click.native="getAccountList()">
                                                    <el-option
                                                            v-for="item in accountList"
                                                            :key="item.id"
                                                            :label="item.title"
                                                            :value="item.id">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                            <el-form-item size="mini">
                                                <el-select placeholder="客户/供应商" clearable filterable default-first-option v-model="recordSearchForm.store_id" @click.native="getStoreListAll()">
                                                    <el-option-group
                                                            v-for="cate in storeListAll"
                                                            :key="cate.title"
                                                            :label="cate.title">
                                                        <el-option
                                                                v-for="item in cate.children"
                                                                :key="item.id"
                                                                :label="item.title"
                                                                :value="item.id">
                                                        </el-option>
                                                    </el-option-group>
                                                </el-select>
                                            </el-form-item>
                                            <el-form-item size="mini">
                                                <el-select  placeholder="项目" clearable filterable default-first-option v-model="recordSearchForm.project_id"  @click.native="getProjectList()">
                                                    <el-option
                                                            v-for="item in projectList"
                                                            :key="item.id"
                                                            :label="item.title"
                                                            :value="item.id">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                            <el-form-item size="mini">
                                                <el-select  placeholder="员工" clearable filterable default-first-option v-model="recordSearchForm.member_id" @click.native="getMemberList()">
                                                    <el-option
                                                            v-for="item in memberList"
                                                            :key="item.id"
                                                            :label="item.name"
                                                            :value="item.id">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                            <el-form-item size="mini">
                                                <el-date-picker class="datePicker" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" v-model="recordSearchForm.begin_date"></el-date-picker>
                                                ~
                                                <el-date-picker class="datePicker" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" v-model="recordSearchForm.end_date"></el-date-picker>
                                            </el-form-item>
                                            <el-form-item size="mini">
                                                <el-input placeholder="备注关键字" v-model="recordSearchForm.memo"></el-input>
                                            </el-form-item>
                                            <el-button type="primary" size="mini" @click="getRecordList(0)">检索</el-button>
                                            <el-divider direction="vertical"></el-divider>
                                            <el-button type="primary" size="mini" @click="getRecordList(1)">全部</el-button>
                                        </el-form>
                                    </div>
                                    <!--账单列表-->
                                    <div class="recordTable">
                                        <template>
                                            <el-table :data="recordList" border stripe>
                                                <el-table-column prop="tally_time" sortable width="120px" label="账单日期">
                                                    <template slot-scope="scope">
                                                        <i class="el-icon-time"></i>
                                                        <span>{{ scope.row.tally_time }}</span>
                                                    </template>
                                                </el-table-column>
                                                <el-table-column prop="category_name" sortable label="分类"></el-table-column>
                                                <el-table-column prop="type_txt" sortable label="类型"></el-table-column>
                                                <el-table-column prop="amount" sortable label="金额"></el-table-column>
                                                <el-table-column prop="account_name" sortable label="账户"></el-table-column>
                                                <el-table-column prop="store_name" sortable width="120px" label="客户/供应商"></el-table-column>
                                                <el-table-column prop="project_name" sortable label="项目"></el-table-column>
                                                <el-table-column prop="memo" label="备注"></el-table-column>
                                                <el-table-column prop="member_name" sortable label="员工"></el-table-column>
                                                <el-table-column prop="memo" label="备注"></el-table-column>
                                                <el-table-column prop="state_txt" label="状态"></el-table-column>
                                            </el-table>
                                        </template>
                                    </div>
                                </el-card>
                            </div>
                        </div>
                    </div>
                </el-tab-pane>
                <el-tab-pane name="category">
                    <span slot="label"><i class="el-icon-s-operation"></i> 分类</span>
                    <div>
                        <el-row>
                            <el-button v-if="categoryType == 1" type="primary" size="small" round>收入分类</el-button>
                            <el-button v-if="categoryType != 1" type="default" size="small" round @click="setCategoryType(1)">收入分类</el-button>
                            <el-button v-if="categoryType == 2" type="primary" size="small" round>支出分类</el-button>
                            <el-button v-if="categoryType != 2" type="default" size="small" round @click="setCategoryType(2)">支出分类</el-button>
                            <el-button type="primary" size="mini" @click="categoryDialog=true" class="frBtn">新增分类</el-button>
                        </el-row>
                        <div class="clearfix" style="margin-top: 10px;"></div>
                        <template>
                            <el-table
                                    :data="categoryListForType"
                                    type="index"
                                    stripe
                                    border
                                    row-key="id"
                                    :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
                                    default-expand-all
                                    style="width: 100%">
                                <el-table-column
                                        type="index"
                                        width="50">
                                </el-table-column>
                                <el-table-column
                                        prop="title"
                                        label="类别名称" sortable>
                                </el-table-column>
                                <el-table-column
                                        prop="type"
                                        label="类型" sortable>
                                    <template slot-scope="scope">
                                        {{ scope.row.type == 1 ? "收入" : "支出" }}
                                    </template>
                                </el-table-column>
                                <el-table-column label="操作">
                                    <template slot-scope="scope">
                                        <el-button type="primary" v-if="scope.row.pid !=0" size="mini" icon="el-icon-edit" circle @click="editCategory(scope.row)"></el-button>
                                        <el-button type="danger" v-if="scope.row.pid !=0" size="mini" icon="el-icon-delete" circle @click="deleteCategoryRow(scope.$index, categoryListForType,scope.row)"></el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </template>
                    </div>
                </el-tab-pane>
                <el-tab-pane name="account">
                    <span slot="label"><i class="el-icon-coordinate"></i> 账户</span>
                    <div>
                        <p style="margin-bottom: 15px;">
                            <span class="contentH3">账户列表</span>
                            <el-button type="primary" size="mini" @click="tallyAccountDialog=true" class="frBtn">新增账户</el-button>
                        </p>
                        <div class="clearfix"></div>
                        <template>
                            <el-table
                                    :data="accountList"
                                    type="index"
                                    stripe
                                    border
                                    show-summary
                                    style="width: 100%">
                                <el-table-column
                                        type="index"
                                        width="50">
                                </el-table-column>
                                <el-table-column
                                        prop="title"
                                        label="名称" sortable>
                                </el-table-column>
                                <el-table-column
                                        prop="money"
                                        label="金额" sortable>
                                </el-table-column>
                                <el-table-column
                                        prop="tag"
                                        label="标签" sortable>
                                </el-table-column>
                                <el-table-column
                                        prop="memo"
                                        label="备注">
                                </el-table-column>
                                <el-table-column label="操作">
                                    <template slot-scope="scope">
                                        <el-button type="primary" size="mini" icon="el-icon-edit" circle @click="editTallyAccount(scope.row)"></el-button>
                                        <el-button type="danger" size="mini" icon="el-icon-delete" circle @click="deleteAccountRow(scope.$index, accountList)"></el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </template>
                    </div>
                </el-tab-pane>
                <el-tab-pane name="store">
                    <span slot="label"><i class="el-icon-shopping-cart-2"></i> 客户/供应商</span>
                    <div>
                        <el-row>
                            <el-button v-if="storeType == 1" type="primary" size="small" round>客户列表</el-button>
                            <el-button v-if="storeType != 1" type="default" size="small" round @click="setStoreType(1)">客户列表</el-button>
                            <el-button v-if="storeType == 2" type="primary" size="small" round>供应商列表</el-button>
                            <el-button v-if="storeType != 2" type="default" size="small" round @click="setStoreType(2)">供应商列表</el-button>
                            <el-button type="primary" size="mini" @click="storeDialog=true" class="frBtn">新增{{storeType == 1 ? "客户" : "供应商" }}</el-button>
                        </el-row>
                        <div class="clearfix" style="margin-top: 10px;"></div>
                        <template>
                            <el-table
                                    :data="storeListForType"
                                    type="index"
                                    stripe
                                    border
                                    style="width: 100%">
                                <el-table-column
                                        type="index"
                                        width="50">
                                </el-table-column>
                                <el-table-column
                                        prop="title"
                                        label="名称" sortable>
                                </el-table-column>
                                <el-table-column label="操作">
                                    <template slot-scope="scope">
                                        <el-button type="primary" size="mini" icon="el-icon-edit" circle @click="editStore(scope.row)"></el-button>
                                        <el-button type="danger" size="mini" icon="el-icon-delete" circle @click="deleteStoreRow(scope.$index, storeListForType)"></el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </template>
                    </div>
                </el-tab-pane>
                <el-tab-pane name="project">
                    <span slot="label"><i class="el-icon-c-scale-to-original"></i> 项目</span>
                    <div>
                        <p style="margin-bottom: 15px;">
                            <span class="contentH3">{{currentTally.title}} / 项目列表</span>
                            <el-button type="primary" size="mini" @click="projectDialog=true" class="frBtn">新增项目</el-button>
                        </p>
                        <div class="clearfix"></div>
                        <template>
                            <el-table
                                    :data="projectList"
                                    type="index"
                                    stripe
                                    border
                                    style="width: 100%">
                                <el-table-column
                                        type="index"
                                        width="50">
                                </el-table-column>
                                <el-table-column
                                        prop="title"
                                        label="名称" sortable>
                                </el-table-column>
                                <el-table-column label="操作">
                                    <template slot-scope="scope">
                                        <el-button type="primary" size="mini" icon="el-icon-edit" circle @click="editProject(scope.row)"></el-button>
                                        <el-button type="danger" size="mini" icon="el-icon-delete" circle @click="deleteProjectRow(scope.$index, projectList)"></el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </template>
                    </div>
                </el-tab-pane>
                <el-tab-pane name="member">
                    <span slot="label"><i class="el-icon-postcard"></i> 员工</span>
                    <div>
                        <p style="margin-bottom: 15px;">
                            <span class="contentH3">{{currentTally.title}} / 员工列表</span>
                            <el-button type="primary" size="mini" @click="this.memberForm = {};memberDialog=true" class="frBtn">新增员工</el-button>
                        </p>
                        <div class="clearfix"></div>
                        <template>
                            <el-table
                                    :data="memberList"
                                    type="index"
                                    stripe
                                    border
                                    style="width: 100%">
                                <el-table-column
                                        type="index"
                                        width="50">
                                </el-table-column>
                                <el-table-column
                                        prop="name"
                                        label="员工名称" sortable>
                                </el-table-column>
                                <el-table-column label="操作">
                                    <template slot-scope="scope">
                                        <el-button type="primary" size="mini" icon="el-icon-edit" circle @click="editMember(scope.row)"></el-button>
                                        <el-button type="danger" size="mini" icon="el-icon-delete" circle @click="deleteMemberRow(scope.$index, memberList)"></el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </template>
                    </div>
                </el-tab-pane>
                <el-tab-pane name="setting">
                    <span slot="label"><i class="el-icon-setting"></i> 设置</span>
                    <div>
                        <p style="margin-bottom: 15px;">
                            <span class="contentH3">{{currentTally.title}} / 设置</span>
                            <el-button type="warning" size="mini" @click="editTally" class="frBtn" icon="el-icon-edit">编辑账本</el-button>
                        </p>
                        <p>
                            公司：{{currentTally.company_title}}
                        </p>
                        <p>
                            所在地：{{ currentTally.city }}.{{ currentTally.province }}
                        </p>
                        <p>
                            备注：{{ currentTally.memo }}
                        </p>
                        <el-divider></el-divider>
                        <p style="margin-bottom: 20px;">
                            <span class="h4">协作管理</span>
                            <el-button type="primary" size="mini" @click="bindUserDialog=true" class="frBtn" icon="el-icon-edit">添加协作者</el-button>
                        </p>

                        <template>
                            <el-table stripe border :data="tallyUsers">
                                <el-table-column
                                        type="index"
                                        width="50">
                                </el-table-column>
                                <el-table-column
                                        prop="username"
                                        label="用户">
                                    <template slot-scope="scope">
                                        {{ scope.row.username || scope.row.mobile }}
                                    </template>
                                </el-table-column>
                                <el-table-column
                                        prop="mobile"
                                        label="手机号">
                                </el-table-column>
                                <el-table-column
                                        prop="role"
                                        label="角色">
                                    <template slot-scope="scope">
                                        <el-tag v-if="scope.row.role == 'admin' " type="success">管理员</el-tag>
                                        <el-tag  v-if="scope.row.role == 'finance'" type="warning">协同者</el-tag>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                        prop="created_time"
                                        label="加入时间">
                                </el-table-column>
                                <el-table-column label="操作">
                                    <template slot-scope="scope">
                                        <span v-if="currentTally.role == 'admin' && scope.row.role != 'admin' " >
                                        <el-button type="danger" size="mini" icon="el-icon-delete" @click="unbindMemberRow(scope.$index, tallyUsers)">移除协作者</el-button>
                                        </span>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </template>
                        <el-divider></el-divider>
                        <p style="margin-bottom: 20px;">
                            <span class="h4">操作日志</span>
                        </p>
                        <template>
                            <el-table stripe :data="tallyLog">
                                <el-table-column
                                        type="index"
                                        width="50">
                                </el-table-column>
                                <el-table-column
                                        prop="created_time"
                                        label="操作时间">
                                </el-table-column>
                                <el-table-column
                                    prop="username"
                                    label="操作人">
                                </el-table-column>
                                <el-table-column
                                        prop="content"
                                        label="日志内容">
                                </el-table-column>
                            </el-table>
                            <p style="margin-top: 10px;">
                                <el-pagination
                                        background
                                        layout="prev, pager, next, total"
                                        :page-size="logPageSize"
                                        :total="logTotalCount"
                                        @current-change="handleLogPageChange"
                                >
                                </el-pagination>
                            </p>
                        </template>
                    </div>
                </el-tab-pane>
            </el-tabs>
        </el-col>
    </el-row>

    <!--账单编辑表单框-->
    <el-dialog title="账单详情" :visible.sync="editDialogRecord">
        <el-form >
            <el-form-item label="活动名称">
                <el-input autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="活动区域">
                <el-select  placeholder="请选择活动区域">
                    <el-option label="区域一" value="shanghai"></el-option>
                    <el-option label="区域二" value="beijing"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="editDialogRecord = false">取 消</el-button>
            <el-button type="primary" @click="editDialogRecord = false">确 定</el-button>
        </div>
    </el-dialog>

    <!--账本新增 编辑表单框-->
    <el-dialog :visible.sync="tallyDialog">
        <h3 slot="title">{{ tallyDialogTitle }}</h3>
        <el-form ref="form" :rules="tallyRules" :model="tallyForm" label-width="80px">
            <el-form-item v-if="tallyForm.id" class="hidden">
                <el-input v-model="tallyForm.id" disabled></el-input>
            </el-form-item>
            <el-form-item label="账本名称" prop="title" required>
                <el-input autocomplete="off" v-model="tallyForm.title" required></el-input>
            </el-form-item>
            <el-form-item label="公司名称">
                <el-input autocomplete="off" v-model="tallyForm.company_title"></el-input>
            </el-form-item>
            <el-form-item label="所在地">
                <el-col :span="11">
                    <el-input v-model="tallyForm.city" placeholder="所在城市"></el-input>
                </el-col>
                <el-col class="line tc" :span="2">-</el-col>
                <el-col :span="11">
                    <el-input v-model="tallyForm.province" placeholder="所在省份"></el-input>
                </el-col>
            </el-form-item>
            <el-form-item label="账本备注">
                <el-input autocomplete="off" v-model="tallyForm.memo"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="tallyDialog = false">取 消</el-button>
            <el-button type="primary" @click="handleTallyForm">确 定</el-button>
        </div>
    </el-dialog>
    <!--分类编辑表单框-->
    <el-dialog :visible.sync="categoryDialog">
        <h3 slot="title">{{ categoryDialogTitle }}</h3>
        <el-form ref="form" :rules="categoryRules" :model="categoryForm" label-width="80px">
            <el-form-item v-if="categoryForm.id" class="hidden">
                <el-input v-model="categoryForm.id" disabled></el-input>
            </el-form-item>
            <el-form-item label="类别名称" prop="title" required>
                <el-input autocomplete="off" v-model="categoryForm.title"></el-input>
            </el-form-item>
            <el-form-item label="上级分类" prop="pid" required>
                <el-select  placeholder="上级分类" v-model="categoryForm.pid">
                    <el-option
                            v-for="item in categoryListForType"
                            :key="item.id"
                            :label="item.title"
                            :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="收支类型">
                <span>{{ categoryType == 1 ? "收入" : "支出"}}</span>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="categoryDialog = false">取 消</el-button>
            <el-button type="primary" @click="handleCategoryForm">确 定</el-button>
        </div>
    </el-dialog>
    <!--账户编辑表单框-->
    <el-dialog :visible.sync="tallyAccountDialog">
        <h3 slot="title">{{ tallyAccountDialogTitle }}</h3>
        <el-form ref="form" :rules="tallyAccountRules" :model="tallyAccountForm" label-width="80px">
            <el-form-item v-if="tallyAccountForm.id" class="hidden">
                <el-input v-model="tallyAccountForm.id" disabled></el-input>
            </el-form-item>
            <el-form-item label="账户名称" prop="title" required>
                <el-input autocomplete="off" v-model="tallyAccountForm.title"></el-input>
            </el-form-item>
            <el-form-item label="账户金额" prop="money" required>
                <el-input autocomplete="off" type="number" v-model="tallyAccountForm.money"></el-input>
            </el-form-item>
            <el-form-item label="标签">
                <el-input autocomplete="off" v-model="tallyAccountForm.tag"></el-input>
            </el-form-item>
            <el-form-item label="备注" prop="memo">
                <el-input autocomplete="off" type="textarea" v-model="tallyAccountForm.memo"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="tallyAccountDialog = false">取 消</el-button>
            <el-button type="primary" @click="handleTallyAccountForm">确 定</el-button>
        </div>
    </el-dialog>
    <!--客户/供应商编辑表单框-->
    <el-dialog :visible.sync="storeDialog">
        <h3 slot="title">{{ storeDialogTitle }}</h3>
        <el-form ref="form" :rules="storeRules" :model="storeForm" label-width="80px">
            <el-form-item v-if="storeForm.id" class="hidden">
                <el-input v-model="storeForm.id" disabled></el-input>
            </el-form-item>
            <el-form-item prop="title" required>
                <span slot="label">{{storeType == 1 ? "客户" : "供应商" }}</span>
                <el-input autocomplete="off" v-model="storeForm.title"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="storeDialog = false">取 消</el-button>
            <el-button type="primary" @click="handleStoreForm">确 定</el-button>
        </div>
    </el-dialog>
    <!--项目编辑表单框-->
    <el-dialog :visible.sync="projectDialog">
        <h3 slot="title">{{ projectDialogTitle }}</h3>
        <el-form ref="form" :rules="projectRules" :model="projectForm" label-width="80px">
            <el-form-item v-if="projectForm.id" class="hidden">
                <el-input v-model="projectForm.id" disabled></el-input>
            </el-form-item>
            <el-form-item label="项目名称" prop="title" required>
                <el-input autocomplete="off" v-model="projectForm.title"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="projectDialog = false">取 消</el-button>
            <el-button type="primary" @click="handleProjectForm">确 定</el-button>
        </div>
    </el-dialog>
    <!--员工编辑表单框-->
    <el-dialog :visible.sync="memberDialog">
        <h3 slot="title">{{ memberDialogTitle }}</h3>
        <el-form ref="form" :rules="memberRules" :model="memberForm" label-width="80px">
            <el-form-item v-if="memberForm.id" class="hidden">
                <el-input v-model="memberForm.id" disabled></el-input>
            </el-form-item>
            <el-form-item label="员工名称" prop="name" required>
                <el-input autocomplete="off" v-model="memberForm.name"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="memberDialog = false">取 消</el-button>
            <el-button type="primary" @click="handleMemberForm">确 定</el-button>
        </div>
    </el-dialog>
    <!--添加协作者表单框-->
    <el-dialog :visible.sync="bindUserDialog">
        <h3 slot="title">添加协作者</h3>
        <el-form ref="form" :rules="bindUserRules" :model="bindUserForm" label-width="80px">
            <el-form-item label="手机号" prop="phone" required>
                <el-input autocomplete="off" v-model="bindUserForm.phone"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="bindUserDialog = false">取 消</el-button>
            <el-button type="primary" @click="handleBindUserForm">确 定</el-button>
        </div>
    </el-dialog>
</div>

<div style="height: 100px;"></div>
<?php echo $this->render('../public/footer.php')?>

<script>
    let CurrDateR = '<?php echo date('Y-m-d');?>';
    let CurrTimeR = '<?php echo date('H:i:s');?>';
    let monthBeginDate = '<?php echo $monthBeginDate;?>';
    let monthEndDate   = '<?php echo $monthEndDate;?>';
    let currentTallyId = '<?php echo $tallyId?>';//当前选中状态的账本
    let loginToken  =  localStorage.getItem('loginToken');
    new Vue({
        el:'#mainContent',
        data() {
            return {
                showImgUploadBox:false,
                dialogImageUrl: '',
                dialogVisible: false,
                editDialogRecord: false,
                tallyDialog:false,
                tallyAccountDialog:false,
                categoryDialog:false,
                storeDialog:false,
                projectDialog:false,
                memberDialog:false,
                bindUserDialog:false,
                logPageSize:10,
                logTotalCount:0,
                currentTally:{},
                tallyForm:{},
                tallyAccountForm:{},
                categoryForm:{},
                storeForm:{},
                projectForm:{},
                memberForm:{},
                bindUserForm:{},
                activeTab:'record',
                tallyDialogTitle:'添加账本',
                tallyAccountDialogTitle:'添加账户',
                categoryDialogTitle:'添加类别',
                storeDialogTitle:'添加客户/供应商',
                projectDialogTitle:'添加项目',
                memberDialogTitle:'添加项目',
                tallyAddType:10,
                categoryType:1,
                storeType:1,
                tallyTypeChanged:true,
                categoryTypeChanged:true,
                tallyRecordForm:{
                    dateR:CurrDateR,
                    timeR:CurrTimeR
                },
                tallyList:[],
                categoryList:[],
                categoryListForType:[],
                storeListForType:[],
                accountList:[],
                storeList:[],
                projectList:[],
                memberList:[],
                storeListAll:[],
                tallyUsers:[],
                tallyLog:[],
                recordSearchForm:{
                    begin_date : monthBeginDate,
                    end_date : monthEndDate,
                },
                recordPeriod: monthBeginDate + ' ～ '+monthEndDate,
                recordCountDebt:{
                    in : 0.00 ,
                    out : 0.00 ,
                    debt : 0.00 ,
                },
                recordList:[],
                upHeaders:{
                    token:loginToken
                },
                recordFormFileList: [],
                tallyRules: {
                    title: [
                        { required: true, message: '请输入账本名称', trigger: 'blur' }
                    ],
                },
                tallyFormRules: {
                    amount: [
                        { required: true, message: '请输入金额', trigger: 'blur' }
                    ],
                },
                tallyAccountRules:{
                    title: [
                        { required: true, message: '请输入账户名称', trigger: 'blur' }
                    ],
                },
                categoryRules:{
                    title: [
                        { required: true, message: '请输入类别名称', trigger: 'blur' }
                    ],
                },
                storeRules:{
                    title: [
                        { required: true, message: '请输入客户/供应商名称', trigger: 'blur' }
                    ],
                },
                projectRules:{
                    title: [
                        { required: true, message: '请输入项目名称', trigger: 'blur' }
                    ],
                },
                memberRules:{
                    name: [
                        { required: true, message: '请输入员工名称', trigger: 'blur' }
                    ],
                },
                bindUserRules:{
                    phone: [
                        { required: true, message: '请输入手机号码', trigger: 'blur' }
                    ],
                },
            }
        },
        computed: {
        },
        mounted:function() {
            if(!logined){
                location.href='/login'
            }
            this._initTally()
        },
        methods: {
            _initTally(){
                // 获取账本列表
                this.getTallyList()
            },
            _initOther(){
                // 初始化类别等数据
                // this.getAccountList()
                // this.getStoreList()
                // this.getProjectList()
                // this.getMemberList()
                // this.getTallyUsersList()
                // this.getRecordList(0)
                // this.getCategoryListForType()
            },
            showTips(type,msg){
                this.$message({
                    type: type,
                    message: msg
                });
            },
            setTallyAddType(type){
                // 类别改变事件
                if(type != this.tallyAddType) {
                    this.tallyAddType = type
                    this.tallyTypeChanged = true
                    this.tallyRecordForm.category_id = null
                    // 触发获取客户/供应商
                    this.getStoreList(type)
                }
            },
            setCategoryType(type){
                // 类别改变事件
                if(type != this.categoryType) {
                    this.categoryType = type
                    this.categoryTypeChanged = true
                    this.getCategoryListForType()
                    // this.tallyRecordForm.category_id = null
                }
            },
            setStoreType(type){
                // 类别改变事件
                if(type != this.storeType) {
                    this.storeType = type
                    this.getStoreList(type,2)
                }
            },
            getTallyList(){
                let that = this
                axios.get('/api/tally/lists',{
                    method: 'get',
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.tallyList = res.data.data
                        if(that.tallyList.length > 0 ) {
                            if(currentTallyId == 0){
                                // 设置第一个为默认账本
                                that.currentTally = that.tallyList[0]
                                currentTallyId  = that.tallyList[0].id
                            }else{
                                that.tallyList.forEach((item,index)=>{
                                    if(item.id == currentTallyId) {
                                        that.currentTally = that.tallyList[index]
                                    }
                                });
                            }
                            // 初始化账本
                            that._initOther();
                        }else{
                            that.showTips('warnning','还没有账本~ 先创建一个吧~')
                        }
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                })
            },
            getCategoryList(){
                if(!this.tallyTypeChanged){
                    return;
                }
                let that = this
                let cateType = 1 //分类类型
                if(this.tallyAddType == 20){
                    cateType = 2
                }
                axios.get('/api/category/lists?tally_id='+currentTallyId+'&type='+cateType,{
                    method: 'get',
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.categoryList = res.data.data
                        that.tallyTypeChanged = false
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                })
            },
            getCategoryListForType(){
                let that = this
                let cateType = this.categoryType
                axios.get('/api/category/lists?tally_id='+currentTallyId+'&type='+cateType,{
                    method: 'get',
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.categoryListForType = res.data.data
                        that.categoryTypeChanged = false
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                })
            },
            getAccountList(){
                let that = this
                axios.get('/api/account/lists?tally_id='+currentTallyId,{
                    method: 'get',
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.accountList = res.data.data
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                })
            },
            getStoreListAll(){
                let that = this
                if(that.storeListAll.length > 0 ) return
                axios.get('/api/store/lists?tally_id='+currentTallyId,{
                    method: 'get',
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.storeListAll = that.branchStoreData(res.data.data)
                        console.log(that.storeListAll)
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                })
            },
            branchStoreData(dataList){
                let st1 = []
                let st2 = []
                dataList.forEach( function (item,index){
                    if(item.type==1){
                        st1.push(item)
                    }else{
                        st2.push(item)
                    }
                });
                return [
                    {"title":"客户","children":st1},
                    {"title":"供应商","children":st2}
                ];
            },
            getStoreList(type,flag=1){
                let that = this
                axios.get('/api/store/lists?type='+type+'&tally_id='+currentTallyId,{
                    method: 'get',
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        if(flag == 2) {
                            that.storeListForType = res.data.data
                        }else{
                            that.storeList = res.data.data
                        }
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                })
            },
            getProjectList(){
                let that = this
                if(that.projectList.length > 0 ) return
                axios.get('/api/project/lists?tally_id='+currentTallyId,{
                    method: 'get',
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.projectList = res.data.data
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                })
            },
            getMemberList(){
                let that = this
                if(that.memberList.length > 0 ) return
                axios.get('/api/member/lists?tally_id='+currentTallyId,{
                    method: 'get',
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.memberList = res.data.data
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                })
            },
            getRecordList(an){
                let that = this
                if(an == 1) {
                    that.recordSearchForm = {
                        begin_date : monthBeginDate,
                        end_date : monthEndDate,
                    }
                } // 获取全部的时候去除筛选条件
                axios.get('/api/tally-record/lists',{
                    method: 'get',
                    headers: {'token': loginToken},
                    params: that.recordSearchForm
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.recordList = res.data.data
                        that.recordPeriod = that.recordSearchForm.begin_date + ' ～ '+ that.recordSearchForm.end_date
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                })
                // 获取债务统计
                axios.get('/api/tally-record/count-debt',{
                    method: 'get',
                    headers: {'token': loginToken},
                    params: that.recordSearchForm
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.recordCountDebt = res.data.data
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                })
            },
            getTallyUsersList(){
                let that = this
                axios.get('/api/tally/users',{
                    method: 'get',
                    headers: {'token': loginToken},
                    params: {id:currentTallyId}
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.tallyUsers = res.data.data
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                })
            },
            getTallyLogList(page){
                let that = this
                axios.get('/api/tally/log',{
                    method: 'get',
                    headers: {'token': loginToken},
                    params: {
                        tally_id:currentTallyId,
                        page:page || 1
                    }
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.tallyLog = res.data.data
                        that.logPageSize = res.data.extra.pageSize
                        that.logTotalCount = res.data.extra.totalCount
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                })
            },
            tallyAddDialog(){
                this.tallyForm = {} //添加表单置空
                this.tallyDialogTitle = '新增账本'
                this.tallyDialog = true;
            },
            editTally(){
                this.tallyForm = this.currentTally
                this.tallyDialogTitle = '编辑账本'
                this.tallyDialog = true;
            },
            editTallyAccount(row){
                this.tallyAccountForm = row
                this.tallyAccountDialogTitle = '编辑账户'
                this.tallyAccountDialog = true;
            },
            editCategory(row){
                this.categoryForm = row
                this.scategoryDialogTitle = '编辑分类'
                this.categoryDialog = true;
            },
            editStore(row){
                this.storeForm = row
                this.storeDialogTitle = '编辑客户/供应商'
                this.storeDialog = true;
            },
            editProject(row){
                this.projectForm = row
                this.projectDialogTitle = '编辑项目'
                this.projectDialog = true;
            },
            editMember(row){
                this.memberForm = row
                this.memberDialogTitle = '编辑员工'
                this.memberDialog = true;
            },
            handleTallyForm(){
                // 处理新增或者添加操作
                let that = this
                let postUrl;
                if(that.tallyForm.id) {
                    postUrl = '/api/tally/edit'
                }else{
                    postUrl = '/api/tally/add'
                }
                axios.post(postUrl,that.tallyForm,{
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.showTips('success','操作成功~')
                        that.getTallyList()
                        that.currentTally = that.tallyForm
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                    that.tallyDialog = false;
                })
            },
            handleRecordForm(){
                // 处理记一笔事件
                let that = this
                let postUrl = '/api/tally-record/add'
                let postData = that.tallyRecordForm
                let attachment = []
                that.recordFormFileList.forEach(v=>{
                    attachment.push(v.url)
                });
                postData.tally_id = currentTallyId // 当前账本ID
                postData.type = this.tallyAddType // 收支类型
                postData.tally_time = postData.dateR + ' '+ postData.timeR //拼账单时间
                postData.attachment = attachment.join(',')
                axios.post(postUrl,postData,{
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.showTips('success','操作成功~')
                        // 追加数据到tallyRecordList
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                    that.tallyDialog = false;
                })
            },
            handleTallyAccountForm(){
                // 处理账户新增&编辑操作
                let that = this
                let postUrl;
                if(that.tallyAccountForm.id) {
                    postUrl = '/api/account/edit'
                }else{
                    postUrl = '/api/account/add'
                }
                axios.post(postUrl,that.tallyAccountForm,{
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.showTips('success','操作成功~')
                        // 追加数据到account
                        that.tallyAccountForm.id = res.data.data.id
                        if(postUrl == '/api/account/add'){
                            that.accountList.push(that.tallyAccountForm)
                        }
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                    that.tallyAccountDialog = false;
                })
            },
            handleCategoryForm(){
                // 处理类别新增操作
                let that = this
                let postUrl;
                if(that.categoryForm.id) {
                    postUrl = '/api/category/edit'
                }else{
                    postUrl = '/api/category/add'
                }
                that.categoryForm.type = that.categoryType
                that.categoryForm.tally_id = currentTallyId
                axios.post(postUrl,that.categoryForm,{
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.showTips('success','操作成功~')
                        that.getCategoryListForType()
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                    that.categoryDialog = false;
                })
            },
            handleStoreForm(){
                // 处理客户/供应商新增/编辑操作
                let that = this
                let postUrl;
                if(that.storeForm.id) {
                    postUrl = '/api/store/edit'
                }else{
                    postUrl = '/api/store/add'
                }
                that.storeForm.tally_id = currentTallyId
                that.storeForm.type = that.storeType
                axios.post(postUrl,that.storeForm,{
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.showTips('success','操作成功~')
                        that.storeForm.id = res.data.data.id
                        that.getStoreList(that.storeType,2)
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                    that.storeDialog = false;
                })
            },
            handleProjectForm(){
                // 处理项目新增/编辑操作
                let that = this
                let postUrl;
                if(that.projectForm.id) {
                    postUrl = '/api/project/edit'
                }else{
                    postUrl = '/api/project/add'
                }
                that.projectForm.tally_id = currentTallyId
                axios.post(postUrl,that.projectForm,{
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.showTips('success','操作成功~')
                        that.projectForm.id = res.data.data.id
                        if(postUrl == '/api/project/add'){
                            that.projectList.push(that.projectForm)
                            that.projectForm = {}
                        }
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                    that.projectDialog = false;
                })
            },
            handleMemberForm(){
                // 处理员工新增/编辑操作
                let that = this
                let postUrl;
                if(that.memberForm.id) {
                    postUrl = '/api/member/edit'
                }else{
                    postUrl = '/api/member/add'
                }
                that.memberForm.tally_id = currentTallyId
                axios.post(postUrl,that.memberForm,{
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.showTips('success','操作成功~')
                        that.memberForm.id = res.data.data.id
                        if(postUrl == '/api/member/add'){
                            that.memberList.push(that.memberForm)
                            that.memberForm = {}
                        }
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                    that.memberDialog = false;
                })
            },
            handleBindUserForm(){
                let that = this
                let postUrl = '/api/tally/bind-finance'
                axios.post(postUrl,{
                    id:currentTallyId,
                    phone:that.bindUserForm.phone
                },{
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status == 'success'){
                        that.showTips('success','操作成功~')
                        that.bindUserDialog = false
                        that.bindUserForm = {}
                        that.getTallyUsersList()
                    }else{
                        that.showTips('error','解析数据失败:'+res.data.error_message)
                    }
                    that.memberDialog = false;
                })
            },
            handleLogPageChange(currentPage){
                // 处理日志记录分页切换
                this.getTallyLogList(currentPage)
            },
            deleteAccountRow(index, rows){
                let that = this
                this.$confirm('确定要删除该行：'+rows[index].title, '提示', {
                    confirmButtonText: '确定',
                    callback: action => {
                        if(action == 'confirm') {
                            // 执行删除操作
                            let postUrl = '/api/account/del'
                            axios.post(postUrl,{id:rows[index].id},{
                                headers: {'token': loginToken},
                            }).then(function(res) {
                                if(res.data.status == 'success'){
                                    that.showTips('success','操作成功~')
                                    rows.splice(index, 1);
                                }else{
                                    that.showTips('error','解析数据失败:'+res.data.error_message)
                                }
                            })
                        }
                    }
                });
            },
            deleteCategoryRow(index,rows,row){
                let that = this
                this.$confirm('确定要删除该行：'+ row.title, '提示', {
                    confirmButtonText: '确定',
                    callback: action => {
                        if(action == 'confirm') {
                            // 执行删除操作
                            let postUrl = '/api/category/del'
                            axios.post(postUrl,{id:row.id},{
                                headers: {'token': loginToken},
                            }).then(function(res) {
                                if(res.data.status == 'success'){
                                    that.showTips('success','操作成功~')
                                    // 删除表格对应项
                                    rows.forEach((item1,index1) => {
                                        item1.children.forEach((item2,index2) => {
                                            if(item2.id == row.id ){
                                                rows[index1].children.splice(index2, 1);
                                            }
                                        })
                                    })
                                }else{
                                    that.showTips('error','解析数据失败:'+res.data.error_message)
                                }
                            })
                        }
                    }
                });
            },
            deleteStoreRow(index, rows){
                let that = this
                this.$confirm('确定要删除该行：'+rows[index].title, '提示', {
                    confirmButtonText: '确定',
                    callback: action => {
                        if(action == 'confirm') {
                            // 执行删除操作
                            let postUrl = '/api/store/del'
                            axios.post(postUrl,{id:rows[index].id},{
                                headers: {'token': loginToken},
                            }).then(function(res) {
                                if(res.data.status == 'success'){
                                    that.showTips('success','操作成功~')
                                    rows.splice(index, 1);
                                }else{
                                    that.showTips('error','解析数据失败:'+res.data.error_message)
                                }
                            })
                        }
                    }
                });
            },
            deleteProjectRow(index, rows){
                let that = this
                this.$confirm('确定要删除该行：'+rows[index].title, '提示', {
                    confirmButtonText: '确定',
                    callback: action => {
                        if(action == 'confirm') {
                            // 执行删除操作
                            let postUrl = '/api/project/del'
                            axios.post(postUrl,{id:rows[index].id},{
                                headers: {'token': loginToken},
                            }).then(function(res) {
                                if(res.data.status == 'success'){
                                    that.showTips('success','操作成功~')
                                    rows.splice(index, 1);
                                }else{
                                    that.showTips('error','解析数据失败:'+res.data.error_message)
                                }
                            })
                        }
                    }
                });
            },
            deleteMemberRow(index, rows){
                let that = this
                this.$confirm('确定要删除该行：'+rows[index].name, '提示', {
                    confirmButtonText: '确定',
                    callback: action => {
                        if(action == 'confirm') {
                            // 执行删除操作
                            let postUrl = '/api/member/del'
                            axios.post(postUrl,{id:rows[index].id},{
                                headers: {'token': loginToken},
                            }).then(function(res) {
                                if(res.data.status == 'success'){
                                    that.showTips('success','操作成功~')
                                    rows.splice(index, 1);
                                }else{
                                    that.showTips('error','解析数据失败:'+res.data.error_message)
                                }
                            })
                        }
                    }
                });
            },
            unbindMemberRow(index,rows){
                let that = this
                this.$confirm('确定要移除该协作用户：'+rows[index].mobile, '提示', {
                    confirmButtonText: '确定',
                    callback: action => {
                        if(action == 'confirm') {
                            // 执行删除操作
                            let postUrl = '/api/tally/unbind-user'
                            axios.post(postUrl,{
                                id:currentTallyId,
                                uid:rows[index].uid
                            },{
                                headers: {'token': loginToken},
                            }).then(function(res) {
                                if(res.data.status == 'success'){
                                    that.showTips('success','操作成功~')
                                    rows.splice(index, 1);
                                }else{
                                    that.showTips('error','解析数据失败:'+res.data.error_message)
                                }
                            })
                        }
                    }
                });
            },
            recordFormFileUploadSuccess(response, file, fileList){
                if(response.status == 'success') {
                    file.url = response.data.url
                    // let fileData = response.data.url.split('/')
                    // let fileName = fileData[fileData.length - 1]
                    this.recordFormFileList.push(file)
                }else{
                    this.showTips('error','上传失败:'+response.error_message)
                }
            },
            recordFormFileRemove(file, fileList){
                this.recordFormFileList = fileList
            },
            handleTabClick(tab,event){
                // 不同tab加载不同数据
                switch (tab.name) {
                    case 'tally':
                        this.getRecordList()
                        break;
                    case 'category':
                        this.getCategoryListForType()
                        break;
                    case 'account':
                        this.getAccountList()
                        break;
                    case 'store':
                        this.getStoreList(1,2)
                        break;
                    case 'member':
                        this.getMemberList()
                        break;
                    case 'project':
                        this.getProjectList()
                        break;
                    case 'setting':
                        this.getTallyUsersList()
                        this.getTallyLogList()
                        break;
                }
                return true ;
            },
        }
    })
</script>
